package com.clouddot.baipai.presenter;


import com.clouddot.baipai.contract.IEvaluateFragmentContract;
import com.clouddot.baipai.http.entity.response.getAllWeekResponse;
import com.clouddot.baipai.http.entity.response.getEvaluateByDayResponse;
import com.clouddot.baipai.http.entity.response.getEvaluateByWeekResponse;

import org.wxy.sdk.base.impl.BasePresenterImpl;

import java.util.ArrayList;

import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
import rx.schedulers.Schedulers;

public class EvaluateFragmentPresenter extends BasePresenterImpl<IEvaluateFragmentContract.IView, IEvaluateFragmentContract.IModel> implements IEvaluateFragmentContract.IPresenter {
    public EvaluateFragmentPresenter(IEvaluateFragmentContract.IView view, IEvaluateFragmentContract.IModel model) {
        super(view, model);
    }


    @Override
    public void getAllWeek() {
        Subscription subscription = mModel.getAllWeek("AllWeekRecord")
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Action1<getAllWeekResponse>() {
                               @Override
                               public void call(getAllWeekResponse response) {
                                   mView.success(2, response);
                               }
                           }
                        , new Action1<Throwable>() {
                            @Override
                            public void call(Throwable throwable) {
                                mView.fail(2, throwable.getMessage());

                            }
                        });
        addSubscription(subscription);
    }

    @Override
    public void getEvaluateByDay(String ObjectType, String ClassId, String CurDate) {
        Subscription subscription = mModel.getEvaluateByDay("ClassValDetail",ObjectType,ClassId,CurDate)
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Action1<ArrayList<getEvaluateByDayResponse>>() {
                               @Override
                               public void call(ArrayList<getEvaluateByDayResponse> response) {
                                   mView.success(1, response);
                               }
                           }
                        , new Action1<Throwable>() {
                            @Override
                            public void call(Throwable throwable) {
                                mView.fail(1, throwable.getMessage());

                            }
                        });
        addSubscription(subscription);
    }

    @Override
    public void getEvaluateByWeek(String ObjectType, String ClassId, String WeekId) {
        Subscription subscription = mModel.getEvaluateByWeek("ClassValCount",ObjectType,ClassId,WeekId)
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Action1<ArrayList<getEvaluateByWeekResponse>>() {
                               @Override
                               public void call(ArrayList<getEvaluateByWeekResponse> response) {
                                   mView.success(3, response);
                               }
                           }
                        , new Action1<Throwable>() {
                            @Override
                            public void call(Throwable throwable) {
                                mView.fail(3, throwable.getMessage());

                            }
                        });
        addSubscription(subscription);
    }

}
